Use GSubprocess instead of GSSubprocess (libgsystem removal)
authorColin Walters <walters@verbum.org>
Fri, 18 Mar 2016 20:46:42 +0000 (16:46 -0400)
committerColin Walters <walters@verbum.org>
Wed, 23 Mar 2016 14:26:01 +0000 (10:26 -0400)
Since we hard-depend on GLib 2.40, we can start using GSubprocess.
This is part of dropping our dependency on libgsystem, which is
deprecated in favor of libglnx (as well as migrating things to GLib).

src/libostree/ostree-bootloader-grub2.c
src/ostree/ot-admin-builtin-switch.c
src/ostree/ot-admin-builtin-upgrade.c
src/ostree/ot-admin-functions.c
src/ostree/ot-admin-functions.h
src/ostree/ot-editor.c

index 42ed5acc9ea168ffbb22842d875b4bd04aa3082c..11316e980f74d15c7c951d49bf75def68f999ccd 100644 (file)
@@ -293,9 +293,9 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader      *bootloader,
   g_autoptr(GFile) efi_new_config_temp = NULL;
   g_autoptr(GFile) efi_orig_config = NULL;
   g_autoptr(GFile) new_config_path = NULL;
-  glnx_unref_object GSSubprocessContext *procctx = NULL;
-  glnx_unref_object GSSubprocess *proc = NULL;
-  g_auto(GStrv) child_env = g_get_environ ();
+  GSubprocessFlags subp_flags = 0;
+  glnx_unref_object GSubprocessLauncher *launcher = NULL;
+  glnx_unref_object GSubprocess *proc = NULL;
   g_autofree char *bootversion_str = g_strdup_printf ("%u", (guint)bootversion);
   g_autoptr(GFile) config_path_efi_dir = NULL;
   g_autofree char *grub2_mkconfig_chroot = NULL;
@@ -337,41 +337,35 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader      *bootloader,
                                                       bootversion);
     }
 
-  procctx = gs_subprocess_context_newv ("grub2-mkconfig", "-o",
-                                        gs_file_get_path_cached (new_config_path),
-                                        NULL);
-  child_env = g_environ_setenv (child_env, "_OSTREE_GRUB2_BOOTVERSION", bootversion_str, TRUE);
+  if (!g_getenv ("OSTREE_DEBUG_GRUB2"))
+    subp_flags |= (G_SUBPROCESS_FLAGS_STDOUT_SILENCE | G_SUBPROCESS_FLAGS_STDERR_SILENCE);
+  
+  launcher = g_subprocess_launcher_new (subp_flags);
+  g_subprocess_launcher_setenv (launcher, "_OSTREE_GRUB2_BOOTVERSION", bootversion_str, TRUE);
   /* We have to pass our state to the child */
   if (self->is_efi)
-    child_env = g_environ_setenv (child_env, "_OSTREE_GRUB2_IS_EFI", "1", TRUE);
-  gs_subprocess_context_set_environment (procctx, child_env);
-  gs_subprocess_context_set_stdout_disposition (procctx, GS_SUBPROCESS_STREAM_DISPOSITION_NULL);
-  if (g_getenv ("OSTREE_DEBUG_GRUB2"))
-    gs_subprocess_context_set_stderr_disposition (procctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
-  else
-    gs_subprocess_context_set_stderr_disposition (procctx, GS_SUBPROCESS_STREAM_DISPOSITION_NULL);
-
+    g_subprocess_launcher_setenv (launcher, "_OSTREE_GRUB2_IS_EFI", "1", TRUE);
+    
   /* We need to chroot() if we're not in /.  This assumes our caller has
    * set up the bind mounts outside.
    */
   if (grub2_mkconfig_chroot != NULL)
-    {
-      gs_subprocess_context_set_child_setup (procctx, grub2_child_setup, grub2_mkconfig_chroot);
-    }
+    g_subprocess_launcher_set_child_setup (launcher, grub2_child_setup, grub2_mkconfig_chroot, NULL);
 
   /* In the current Fedora grub2 package, this script doesn't even try
      to be atomic; it just does:
 
-cat ${grub_cfg}.new > ${grub_cfg}
-rm -f ${grub_cfg}.new
+     cat ${grub_cfg}.new > ${grub_cfg}
+     rm -f ${grub_cfg}.new
 
      Upstream is fixed though.
   */
-  proc = gs_subprocess_new (procctx, cancellable, error);
-  if (!proc)
-    goto out;
+  proc = g_subprocess_launcher_spawn (launcher, error,
+                                      "grub2-mkconfig", "-o",
+                                      gs_file_get_path_cached (new_config_path),
+                                      NULL);
 
-  if (!gs_subprocess_wait_sync_check (proc, cancellable, error))
+  if (!g_subprocess_wait_check (proc, cancellable, error))
     goto out;
 
   /* Now let's fdatasync() for the new file */
index 4d82ca6b3bf8412c9b1c7bf26d741ddd2a8aacd9..0e0101a9b8f38f8f46a30290fd9a461ec20c3d86 100644 (file)
@@ -163,16 +163,11 @@ ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GErro
   if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
     goto out;
   
-  {
-    g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
-      
-    if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
-      {
-        gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
-                                       cancellable, error,
-                                       "systemctl", "reboot", NULL);
-      }
-  }
+  if (opt_reboot)
+    {
+      if (!ot_admin_execve_reboot (sysroot, error))
+        goto out;
+    }
 
   ret = TRUE;
  out:
index 90d0ce98dc5f8a56a08f8ef8aa6c30cd233e32e6..5d4796ac5853d893a8c1db145eba7cc01916d585 100644 (file)
@@ -133,16 +133,13 @@ ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GErr
     }
   else
     {
-      g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
-
       if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
         goto out;
 
-      if (opt_reboot && g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
+      if (opt_reboot)
         {
-          gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
-                                         cancellable, error,
-                                         "systemctl", "reboot", NULL);
+          if (!ot_admin_execve_reboot (sysroot, error))
+            goto out;
         }
     }
 
index c818a00c6b182c35978f4834f1269ae56705f633..bc9034e136f7195e6af0042cd4dfb279272aa4ce 100644 (file)
@@ -155,3 +155,20 @@ ot_admin_sysroot_lock (OstreeSysroot  *sysroot,
   g_main_context_unref (state.mainctx);
   return ret;
 }
+
+gboolean
+ot_admin_execve_reboot (OstreeSysroot *sysroot, GError **error)
+{
+  g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
+      
+  if (g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
+    {
+      if (execl ("systemctl", "systemctl", "reboot", NULL) < 0)
+        {
+          glnx_set_error_from_errno (error);
+          return FALSE;
+        }
+    }
+
+  return TRUE;
+}
index 67164ca5f83b181fed139735d3341f798dad1089..8c0cf8ee76c8c5aec7d486a0421ef88ae381da18 100644 (file)
@@ -45,5 +45,8 @@ gboolean
 ot_admin_sysroot_lock (OstreeSysroot  *sysroot,
                        GError        **error);
 
+gboolean
+ot_admin_execve_reboot (OstreeSysroot *sysroot,
+                        GError **error);
 
 G_END_DECLS
index 2b2101f6af4bf4f7dc5b6425061b2d5aa4f907f1..4c29c81e35c6c700dd0dda9620f11670dfb1fc01 100644 (file)
@@ -62,8 +62,7 @@ ot_editor_prompt (OstreeRepo *repo,
                   GCancellable *cancellable,
                   GError **error)
 {
-  glnx_unref_object GSSubprocessContext *ctx = NULL;
-  glnx_unref_object GSSubprocess *proc = NULL;
+  glnx_unref_object GSubprocess *proc = NULL;
   g_autoptr(GFile) file = NULL;
   g_autoptr(GFileIOStream) io = NULL;
   GOutputStream *output;
@@ -92,16 +91,11 @@ ot_editor_prompt (OstreeRepo *repo,
     g_autofree char *quoted_file = g_shell_quote (gs_file_get_path_cached (file));
     args = g_strconcat (editor, " ", quoted_file, NULL);
   }
-  ctx = gs_subprocess_context_newv ("/bin/sh", "-c", args, NULL);
-  gs_subprocess_context_set_stdin_disposition (ctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
-  gs_subprocess_context_set_stdout_disposition (ctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
-  gs_subprocess_context_set_stderr_disposition (ctx, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT);
 
-  proc = gs_subprocess_new (ctx, cancellable, error);
-  if (proc == NULL)
-    goto out;
+  proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_INHERIT, error, 
+                           "/bin/sh", "-c", args, NULL);
 
-  if (!gs_subprocess_wait_sync_check (proc, cancellable, error))
+  if (!g_subprocess_wait_check (proc, cancellable, error))
     {
       g_prefix_error (error, "There was a problem with the editor '%s'", editor);
       goto out;